﻿using System;
using System.IO;
using System.Windows;
using System.Windows.Forms;

namespace SocketService
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        ServiceMainWindowViewModel mainWindowViewModel = new ServiceMainWindowViewModel();
        WindowState ws;
        WindowState wsl;
        NotifyIcon notifyIcon;
        public MainWindow()
        {
            InitializeComponent();
            DataContext = mainWindowViewModel;
            icon();
            //保证窗体显示在上方。 
            wsl = WindowState;
        }
        private void icon()
        {
            string path = System.IO.Path.GetFullPath(@"server_128px_1221470_easyicon.net.ico");
            if (File.Exists(path))
            {
                this.notifyIcon = new NotifyIcon();
                this.notifyIcon.BalloonTipText = "IIS管理器ByNine"; //设置程序启动时显示的文本
                this.notifyIcon.Text = "IIS管理器ByNine";//最小化到托盘时，鼠标点击时显示的文本
                System.Drawing.Icon icon = new System.Drawing.Icon(path);//程序图标 
                this.notifyIcon.Icon = icon;
                this.notifyIcon.Visible = true;
                notifyIcon.MouseDoubleClick += OnNotifyIconDoubleClick;
                this.notifyIcon.ShowBalloonTip(1000);
            }

        }
        private void OnNotifyIconDoubleClick(object sender, EventArgs e)
        {
            this.Show();
            WindowState = wsl;
        }
        private void Window_StateChanged(object sender, EventArgs e)
        {
            ws = this.WindowState;
            if (ws == WindowState.Minimized)
            {
                this.Hide();
            }
        }
    }
}
